// 导入createSlice函数
import { createSlice } from "@reduxjs/toolkit";

// 创建一个名为user的slice
const userSlice = createSlice({
  // slice的名称
  name: "user",
  initialState: {
    accessToken: "",
    refreshToken: "",
    userInfo: {
      avator: ""
    },
  },
  reducers: {
    loginSuccess(state, action) {
      console.log('data', action.payload);
      state.accessToken = action.payload.accessToken;
      state.refreshToken = action.payload.refreshToken;
      state.userInfo = action.payload.userInfo;
    },
    quitLogin(state) {
      state.accessToken = ""
      state.refreshToken  = ""
      state.userInfo = ""
    }
  },
});

export default userSlice;
export const { loginSuccess, quitLogin } = userSlice.actions;
